library("FRESA.CAD")
library(readxl)
library(igraph)
library(umap)
library(tsne)
library(entropy)
op <- par(no.readonly = TRUE)
pander::panderOptions('digits', 3)
pander::panderOptions('table.split.table', 400)
pander::panderOptions('keep.trailing.zeros',TRUE)
dataGI <- as.data.frame(read_excel("~/GitHub/LatentBiomarkers/Data/GI/data.xlsx", sheet = "Sheet1"))
dataGI$ID <- NULL
table(dataGI$V2)
#>
#> 1 2
#> 76 76
dataSet1 <- subset(dataGI,V2==1)
class <- dataSet1$V1
dataSet1$V1 <- NULL
dataSet1$V2 <- NULL
colnames(dataSet1) <- paste(colnames(dataSet1),"WL",sep="_")
dataSet2 <- subset(dataGI,V2==2)
dataSet2$V1 <- NULL
dataSet2$V2 <- NULL
colnames(dataSet2) <- paste(colnames(dataSet2),"NBI",sep="_")
dataGI <- cbind(dataSet1,dataSet2)
dataGI$class <- 1*(class > 1)
table(dataGI$class)
#>
#> 0 1
#> 21 55
studyName <- "GI"
dataframe <- dataGI
outcome <- "class"
TopVariables <- 10
thro <- 0.80
cexheat = 0.15
Some libraries
library(psych)
library(whitening)
library("vioplot")
library("rpart")
pander::pander(c(rows=nrow(dataframe),col=ncol(dataframe)-1))
| rows | col |
|---|---|
| 76 | 1396 |
pander::pander(table(dataframe[,outcome]))
| 0 | 1 |
|---|---|
| 21 | 55 |
varlist <- colnames(dataframe)
varlist <- varlist[varlist != outcome]
largeSet <- length(varlist) > 1500
Scaling and removing near zero variance columns and highly co-linear(r>0.99999) columns
### Some global cleaning
sdiszero <- apply(dataframe,2,sd) > 1.0e-16
dataframe <- dataframe[,sdiszero]
varlist <- colnames(dataframe)[colnames(dataframe) != outcome]
tokeep <- c(as.character(correlated_Remove(dataframe,varlist,thr=0.99999)),outcome)
dataframe <- dataframe[,tokeep]
varlist <- colnames(dataframe)
varlist <- varlist[varlist != outcome]
iscontinous <- sapply(apply(dataframe,2,unique),length) >= 5 ## Only variables with enough samples
dataframeScaled <- FRESAScale(dataframe,method="OrderLogit")$scaledData
numsub <- nrow(dataframe)
if (numsub > 1000) numsub <- 1000
if (!largeSet)
{
hm <- heatMaps(data=dataframeScaled[1:numsub,],
Outcome=outcome,
Scale=TRUE,
hCluster = "row",
xlab="Feature",
ylab="Sample",
srtCol=45,
srtRow=45,
cexCol=cexheat,
cexRow=cexheat
)
par(op)
}
The heat map of the data
if (!largeSet)
{
par(cex=0.6,cex.main=0.85,cex.axis=0.7)
#cormat <- Rfast::cora(as.matrix(dataframe[,varlist]),large=TRUE)
cormat <- cor(dataframe[,varlist],method="pearson")
cormat[is.na(cormat)] <- 0
gplots::heatmap.2(abs(cormat),
trace = "none",
# scale = "row",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "Original Correlation",
cexRow = cexheat,
cexCol = cexheat,
srtCol=45,
srtRow=45,
key.title=NA,
key.xlab="|Pearson Correlation|",
xlab="Feature", ylab="Feature")
diag(cormat) <- 0
print(max(abs(cormat)))
}
[1]
0.9999797
DEdataframe <- IDeA(dataframe,verbose=TRUE,thr=thro)
#>
#> V644_WL V599_WL V497_NBI V497_WL V49_NBI V443_WL
#> V3_WL V4_WL V5_WL V6_WL V7_WL V8_WL
#> 0.7462069 0.6082759 0.5172414 0.5158621 0.5365517 0.5310345
#>
#> Included: 725 , Uni p: 0.0002068966 , Base Size: 6 , Rcrit: 0.3949911
#>
#>
1 <R=0.942,thr=0.950>, Top: 69< 48 >[Fa= 69 ]( 69 , 178 , 0 ),<|><>Tot Used: 247 , Added: 178 , Zero Std: 0 , Max Cor: 1.000
#>
2 <R=0.919,thr=0.950>, Top: 15< 25 >[Fa= 84 ]( 15 , 88 , 69 ),<|><>Tot Used: 308 , Added: 88 , Zero Std: 0 , Max Cor: 0.999
#>
3 <R=0.910,thr=0.950>, Top: 12< 5 >[Fa= 94 ]( 10 , 40 , 84 ),<|><>Tot Used: 318 , Added: 40 , Zero Std: 0 , Max Cor: 0.989
#>
4 <R=0.903,thr=0.950>, Top: 4< 2 >[Fa= 98 ]( 4 , 7 , 94 ),<|><>Tot Used: 321 , Added: 7 , Zero Std: 0 , Max Cor: 0.950
#>
5 <R=0.901,thr=0.900>, Top: 92< 1 >[Fa= 147 ]( 88 , 148 , 98 ),<|><>Tot Used: 469 , Added: 148 , Zero Std: 0 , Max Cor: 0.949
#>
6 <R=0.866,thr=0.900>, Top: 16< 1 >[Fa= 154 ]( 16 , 17 , 147 ),<|><>Tot Used: 487 , Added: 17 , Zero Std: 0 , Max Cor: 0.907
#>
7 <R=0.860,thr=0.900>, Top: 1< 1 >[Fa= 155 ]( 1 , 1 , 154 ),<|><>Tot Used: 489 , Added: 1 , Zero Std: 0 , Max Cor: 0.900
#>
8 <R=0.860,thr=0.800>, Top: 98< 2 >[Fa= 195 ]( 92 , 152 , 155 ),<|><>Tot Used: 573 , Added: 152 , Zero Std: 0 , Max Cor: 0.926
#>
9 <R=0.855,thr=0.900>, Top: 2< 1 >[Fa= 196 ]( 2 , 2 , 195 ),<|><>Tot Used: 574 , Added: 2 , Zero Std: 0 , Max Cor: 0.897
#>
10 <R=0.852,thr=0.800>, Top: 29< 1 >[Fa= 205 ]( 26 , 38 , 196 ),<|><>Tot Used: 601 , Added: 38 , Zero Std: 0 , Max Cor: 0.894
#>
11 <R=0.849,thr=0.800>, Top: 8< 2 >[Fa= 210 ]( 7 , 11 , 205 ),<|><>Tot Used: 613 , Added: 11 , Zero Std: 0 , Max Cor: 0.884
#>
12 <R=0.857,thr=0.800>, Top: 5< 1 >[Fa= 213 ]( 4 , 5 , 210 ),<|><>Tot Used: 620 , Added: 5 , Zero Std: 0 , Max Cor: 0.884
#>
13 <R=0.884,thr=0.800>, Top: 1< 1 >[Fa= 213 ]( 1 , 1 , 213 ),<|><>Tot Used: 620 , Added: 1 , Zero Std: 0 , Max Cor: 0.884
#>
14 <R=0.864,thr=0.800>, Top: 2< 1 >[Fa= 213 ]( 1 , 1 , 213 ),<|><>Tot Used: 620 , Added: 1 , Zero Std: 0 , Max Cor: 0.881
#>
15 <R=0.881,thr=0.800>, Top: 1< 1 >[Fa= 213 ]( 1 , 1 , 213 ),<|><>Tot Used: 620 , Added: 1 , Zero Std: 0 , Max Cor: 0.868
#>
16 <R=0.847,thr=0.800>, Top: 2< 1 >[Fa= 213 ]( 1 , 1 , 213 ),<|><>Tot Used: 620 , Added: 1 , Zero Std: 0 , Max Cor: 0.814
#>
17 <R=0.814,thr=0.800>, Top: 1< 1 >[Fa= 213 ]( 1 , 1 , 213 ),<|><>Tot Used: 620 , Added: 1 , Zero Std: 0 , Max Cor: 0.799
#>
18 <R=0.799,thr=0.800>
#>
[ 18 ], 0.7993308 Decor Dimension: 620 Nused: 620 . Cor to Base: 369 , ABase: 725 , Outcome Base: 0
#>
varlistc <- colnames(DEdataframe)[colnames(DEdataframe) != outcome]
pander::pander(sum(apply(dataframe[,varlist],2,var)))
7.73e+08
pander::pander(sum(apply(DEdataframe[,varlistc],2,var)))
1.55e+08
pander::pander(entropy(discretize(unlist(dataframe[,varlist]), 256)))
0.306
pander::pander(entropy(discretize(unlist(DEdataframe[,varlistc]), 256)))
0.217
varratio <- attr(DEdataframe,"VarRatio")
pander::pander(tail(varratio))
| La_V698_WL | La_V699_WL | La_V677_WL | La_V681_WL | La_V692_WL | La_V468_NBI |
|---|---|---|---|---|---|
| 4.59e-05 | 4.01e-05 | 3.78e-05 | 3.72e-05 | 3.61e-05 | 1.73e-06 |
if (!largeSet)
{
par(cex=0.6,cex.main=0.85,cex.axis=0.7)
UPLTM <- attr(DEdataframe,"UPLTM")
gplots::heatmap.2(1.0*(abs(UPLTM)>0),
trace = "none",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "Decorrelation matrix",
cexRow = cexheat,
cexCol = cexheat,
srtCol=45,
srtRow=45,
key.title=NA,
key.xlab="|Beta|>0",
xlab="Output Feature", ylab="Input Feature")
par(op)
}
Displaying the features associations
par(op)
clustable <- c("To many variables")
transform <- attr(DEdataframe,"UPLTM") != 0
tnames <- colnames(transform)
colnames(transform) <- str_remove_all(colnames(transform),"La_")
transform <- abs(transform*cor(dataframe[,rownames(transform)])) # The weights are proportional to the observed correlation
fscore <- attr(DEdataframe,"fscore")
VertexSize <- fscore # The size depends on the variable independence relevance (fscore)
names(VertexSize) <- str_remove_all(names(VertexSize),"La_")
VertexSize <- 10*(VertexSize-min(VertexSize))/(max(VertexSize)-min(VertexSize)) # Normalization
VertexSize <- VertexSize[rownames(transform)]
rsum <- apply(1*(transform !=0),1,sum) + 0.01*VertexSize + 0.001*varratio[tnames]
csum <- apply(1*(transform !=0),2,sum) + 0.01*VertexSize + 0.001*varratio[tnames]
ntop <- min(10,length(rsum))
topfeatures <- unique(c(names(rsum[order(-rsum)])[1:ntop],names(csum[order(-csum)])[1:ntop]))
rtrans <- transform[topfeatures,]
csum <- (apply(1*(rtrans !=0),2,sum) > 1*(colnames(rtrans) %in% topfeatures))
rtrans <- rtrans[,csum]
topfeatures <- unique(c(topfeatures,colnames(rtrans)))
print(ncol(transform))
[1] 620
transform <- transform[topfeatures,topfeatures]
print(ncol(transform))
[1] 161
if (ncol(transform)>100)
{
csum <- apply(1*(transform !=0),1,sum)
csum <- csum[csum > 1]
csum <- csum + 0.01*VertexSize[names(csum)]
csum <- csum[order(-csum)]
tpsum <- min(20,length(csum))
trsum <- rownames(transform)[rownames(transform) %in% names(csum[1:tpsum])]
rtrans <- transform[trsum,]
topfeatures <- unique(c(rownames(rtrans),colnames(rtrans)))
transform <- transform[topfeatures,topfeatures]
if (nrow(transform) > 150)
{
csum <- apply(1*(rtrans != 0 ),2,sum)
csum <- csum + 0.01*VertexSize[names(csum)]
csum <- csum[order(-csum)]
tpsum <- min(130,length(csum))
csum <- rownames(transform)[rownames(transform) %in% names(csum[1:tpsum])]
csum <- unique(c(trsum,csum))
transform <- transform[csum,csum]
}
print(ncol(transform))
}
[1] 130
if (ncol(transform) < 150)
{
gplots::heatmap.2(transform,
trace = "none",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "Red Decorrelation matrix",
cexRow = cexheat,
cexCol = cexheat,
srtCol=45,
srtRow=45,
key.title=NA,
key.xlab="|Beta|>0",
xlab="Output Feature", ylab="Input Feature")
par(op)
VertexSize <- VertexSize[colnames(transform)]
gr <- graph_from_adjacency_matrix(transform,mode = "directed",diag = FALSE,weighted=TRUE)
gr$layout <- layout_with_fr
# fc <- cluster_optimal(gr)
fc <- cluster_walktrap (gr,steps=50)
plot(fc, gr,
edge.width = 2*E(gr)$weight,
vertex.size=VertexSize,
edge.arrow.size=0.5,
edge.arrow.width=0.5,
vertex.label.cex=(0.15+0.05*VertexSize),
vertex.label.dist=0.5 + 0.05*VertexSize,
main="Top Feature Association")
varratios <- varratio
fscores <- fscore
names(varratios) <- str_remove_all(names(varratios),"La_")
names(fscores) <- str_remove_all(names(fscores),"La_")
dc <- getLatentCoefficients(DEdataframe)
theCharformulas <- attr(dc,"LatentCharFormulas")
clustable <- as.data.frame(cbind(Variable=fc$names,
Formula=as.character(theCharformulas[paste("La_",fc$names,sep="")]),
Class=fc$membership,
ResidualVariance=round(varratios[fc$names],3),
Fscore=round(fscores[fc$names],3)
)
)
rownames(clustable) <- str_replace_all(rownames(clustable),"__","_")
clustable$Variable <- NULL
clustable$Class <- as.integer(clustable$Class)
clustable$ResidualVariance <- as.numeric(clustable$ResidualVariance)
clustable$Fscore <- as.numeric(clustable$Fscore)
clustable <- clustable[order(-clustable$Fscore),]
clustable <- clustable[order(clustable$Class),]
clustable <- clustable[clustable$Fscore >= -1,]
topv <- min(50,nrow(clustable))
clustable <- clustable[1:topv,]
}
pander::pander(clustable)
| Formula | Class | ResidualVariance | Fscore | |
|---|---|---|---|---|
| V625_WL | + V625_WL - (6.880)V639_WL + (6.292)V644_WL | 1 | 0.018 | 8 |
| V620_WL | + V620_WL - (1.557)V622_WL + (0.546)V625_WL | 1 | 0.006 | 3 |
| V622_WL | + V622_WL - (1.121)V625_WL | 1 | 0.007 | 1 |
| V616_WL | + V616_WL - (2.130)V620_WL + (1.148)V625_WL | 1 | 0.006 | -1 |
| V623_WL | + V623_WL - (1.070)V625_WL | 1 | 0.003 | -1 |
| V624_WL | + V624_WL - (1.032)V625_WL | 1 | 0.001 | -1 |
| V649_WL | - (0.862)V644_WL + V649_WL | 2 | 0.005 | 2 |
| V675_WL | + (0.886)V644_WL - (0.027)V649_WL - (1.624)V652_WL + V675_WL | 3 | 0.004 | 22 |
| V682_WL | + (0.232)V675_WL - (1.188)V679_WL + V682_WL | 3 | 0.001 | 17 |
| V691_WL | + (0.706)V675_WL - (1.647)V682_WL + V691_WL | 3 | 0.000 | 4 |
| V679_WL | - (0.906)V675_WL + V679_WL | 3 | 0.002 | 2 |
| V696_WL | + (0.943)V675_WL - (1.842)V682_WL + V696_WL | 3 | 0.001 | 1 |
| V676_WL | - (0.974)V675_WL + V676_WL | 3 | 0.001 | 0 |
| V695_WL | + (0.292)V675_WL - (0.405)V682_WL - (0.841)V691_WL + V695_WL | 3 | 0.000 | -1 |
| V683_WL | + (0.025)V675_WL - (1.005)V682_WL + V683_WL | 3 | 0.000 | -1 |
| V687_WL | + (0.374)V675_WL - (1.331)V682_WL + V687_WL | 3 | 0.000 | -1 |
| V198_NBI | NA | 4 | 1.000 | 18 |
| V184_NBI | + V184_NBI - (48.677)V198_NBI | 4 | 0.346 | 4 |
| V232_WL | + V232_WL - (17.711)V198_NBI | 4 | 0.339 | 2 |
| V180_NBI | + V180_NBI - (0.850)V198_NBI | 4 | 0.195 | 2 |
| V216_NBI | - (1.054)V198_NBI + V216_NBI | 4 | 0.113 | 1 |
| V224_NBI | - (1.084)V198_NBI + V224_NBI | 4 | 0.092 | 1 |
| V188_NBI | + V188_NBI - (1.022)V198_NBI | 4 | 0.064 | 0 |
| V228_NBI | - (4.83e-03)V198_NBI - (1.013)V224_NBI + V228_NBI | 4 | 0.012 | 0 |
| V296_NBI | - (13.104)V198_NBI + V296_NBI | 4 | 0.192 | 0 |
| V639_WL | + V639_WL - (1.186)V644_WL | 5 | 0.006 | 4 |
| V644_WL | NA | 6 | 1.000 | 50 |
| V652_WL | + (0.313)V644_WL - (1.276)V649_WL + V652_WL | 6 | 0.002 | 23 |
| V662_WL | + (0.570)V644_WL - (1.474)V652_WL + V662_WL | 6 | 0.002 | 3 |
| V667_WL | + (0.350)V644_WL - (0.624)V652_WL - (0.628)V662_WL + V667_WL | 6 | 0.001 | 2 |
| V658_WL | + (0.417)V644_WL - (1.370)V652_WL + V658_WL | 6 | 0.002 | 2 |
| V642_WL | + V642_WL - (1.076)V644_WL | 6 | 0.001 | 0 |
| V646_WL | - (0.944)V644_WL + V646_WL | 6 | 0.001 | 0 |
| V673_WL | - (0.059)V644_WL + (0.366)V652_WL - (1.304)V667_WL + V673_WL | 6 | 0.000 | -1 |
| V643_WL | + V643_WL - (1.033)V644_WL | 6 | 0.001 | -1 |
| V645_WL | - (0.978)V644_WL + V645_WL | 6 | 0.000 | -1 |
| V653_WL | + (0.059)V644_WL - (1.048)V652_WL + V653_WL | 6 | 0.000 | -1 |
| V228_WL | - (1.150)V192_WL + V228_WL | 7 | 0.171 | 12 |
| V182_WL | + V182_WL - (0.687)V228_WL | 7 | 0.086 | 1 |
| V194_WL | + V194_WL - (0.843)V228_WL | 7 | 0.038 | 0 |
| V208_WL | + V208_WL - (1.128)V228_WL | 7 | 0.046 | 0 |
| V216_WL | + V216_WL - (0.812)V228_WL | 7 | 0.062 | 0 |
| V172_WL | + V172_WL - (7.270)V228_WL | 7 | 0.088 | -1 |
| V196_WL | + V196_WL - (0.982)V228_WL | 7 | 0.044 | -1 |
| V220_WL | + V220_WL - (0.440)V228_WL | 7 | 0.063 | -1 |
| V224_WL | + V224_WL - (0.983)V228_WL | 7 | 0.013 | -1 |
| V288_WL | - (0.452)V228_WL + V288_WL | 7 | 0.069 | -1 |
| V424_WL | - (81.331)V208_WL + (91.739)V228_WL + V424_WL | 7 | 0.296 | -1 |
| V635_WL | + V635_WL - (1.913)V639_WL + (0.915)V644_WL | 8 | 0.003 | 8 |
| V630_WL | + V630_WL - (1.924)V635_WL + (1.027)V644_WL | 8 | 0.003 | 1 |
par(op)
if (!largeSet)
{
cormat <- cor(DEdataframe[,varlistc],method="pearson")
cormat[is.na(cormat)] <- 0
gplots::heatmap.2(abs(cormat),
trace = "none",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "Correlation after ILAA",
cexRow = cexheat,
cexCol = cexheat,
srtCol=45,
srtRow=45,
key.title=NA,
key.xlab="|Pearson Correlation|",
xlab="Feature", ylab="Feature")
par(op)
diag(cormat) <- 0
print(max(abs(cormat)))
}
[1]
0.9419448
classes <- unique(dataframe[1:numsub,outcome])
raincolors <- rainbow(length(classes))
names(raincolors) <- classes
topvars <- univariate_BinEnsemble(dataframe,outcome)
lso <- LASSO_MIN(formula(paste(outcome,"~.")),dataframe,family="binomial")
topvars <- unique(c(names(topvars),lso$selectedfeatures))
pander::pander(head(topvars))
V172_WL, V474_NBI, V477_NBI, V220_WL, V220_NBI and V470_NBI
# names(topvars)
#if (nrow(dataframe) < 1000)
#{
datasetframe.umap = umap(scale(dataframe[1:numsub,topvars]),n_components=2)
# datasetframe.umap = umap(dataframe[1:numsub,varlist],n_components=2)
plot(datasetframe.umap$layout,xlab="U1",ylab="U2",main="UMAP: Original",t='n')
text(datasetframe.umap$layout,labels=dataframe[1:numsub,outcome],col=raincolors[dataframe[1:numsub,outcome]+1])
#}
varlistcV <- names(varratio[varratio >= 0.01])
topvars <- univariate_BinEnsemble(DEdataframe[,varlistcV],outcome)
lso <- LASSO_MIN(formula(paste(outcome,"~.")),DEdataframe[,varlistcV],family="binomial")
topvars <- unique(c(names(topvars),lso$selectedfeatures))
pander::pander(head(topvars))
V474_NBI, V169_WL, V492_NBI, V499_NBI, V280_NBI and V499_WL
varlistcV <- varlistcV[varlistcV != outcome]
# DEdataframe[,outcome] <- as.numeric(DEdataframe[,outcome])
#if (nrow(dataframe) < 1000)
#{
datasetframe.umap = umap(scale(DEdataframe[1:numsub,topvars]),n_components=2)
# datasetframe.umap = umap(DEdataframe[1:numsub,varlistcV],n_components=2)
plot(datasetframe.umap$layout,xlab="U1",ylab="U2",main="UMAP: After ILAA",t='n')
text(datasetframe.umap$layout,labels=DEdataframe[1:numsub,outcome],col=raincolors[DEdataframe[1:numsub,outcome]+1])
#}
univarRAW <- uniRankVar(varlist,
paste(outcome,"~1"),
outcome,
dataframe,
rankingTest="AUC")
100 : V102_WL 200 : V288_WL 300 : V535_WL 400 : V635_WL 500 :
V37_NBI
600 : V137_NBI 700 : V470_NBI
univarDe <- uniRankVar(varlistc,
paste(outcome,"~1"),
outcome,
DEdataframe,
rankingTest="AUC",
)
100 : La_V102_WL 200 : La_V288_WL 300 : La_V535_WL 400 : La_V635_WL
500 : V37_NBI
600 : La_V137_NBI 700 : La_V470_NBI
univariate_columns <- c("caseMean","caseStd","controlMean","controlStd","controlKSP","ROCAUC")
##top variables
topvar <- c(1:length(varlist)) <= TopVariables
tableRaw <- univarRAW$orderframe[topvar,univariate_columns]
pander::pander(tableRaw)
| caseMean | caseStd | controlMean | controlStd | controlKSP | ROCAUC | |
|---|---|---|---|---|---|---|
| V172_WL | 3.55e+03 | 1.78e+03 | 1046.667 | 537.2409 | 0.718095 | 0.933 |
| V220_NBI | 2.01e+02 | 1.20e+02 | 51.524 | 27.8220 | 0.747592 | 0.929 |
| V220_WL | 1.96e+02 | 1.07e+02 | 52.381 | 42.7370 | 0.097268 | 0.927 |
| V477_NBI | 6.18e-02 | 2.98e-02 | 0.149 | 0.1717 | 0.000358 | 0.925 |
| V169_NBI | 1.26e+03 | 8.24e+02 | 346.619 | 198.5476 | 0.350000 | 0.920 |
| V196_NBI | 4.52e+02 | 2.51e+02 | 134.238 | 66.3226 | 0.410564 | 0.920 |
| V182_NBI | 3.44e+02 | 2.17e+02 | 95.190 | 48.8412 | 0.793090 | 0.915 |
| V470_NBI | 3.79e-01 | 1.34e-01 | 0.188 | 0.0682 | 0.948083 | 0.913 |
| V182_WL | 3.17e+02 | 1.69e+02 | 96.476 | 87.3691 | 0.142781 | 0.912 |
| V474_NBI | 3.40e+00 | 3.13e-01 | 2.680 | 0.5481 | 0.222068 | 0.912 |
topLAvar <- univarDe$orderframe$Name[str_detect(univarDe$orderframe$Name,"La_")]
topLAvar <- unique(c(univarDe$orderframe$Name[topvar],topLAvar[1:as.integer(TopVariables/2)]))
finalTable <- univarDe$orderframe[topLAvar,univariate_columns]
pander::pander(finalTable)
| caseMean | caseStd | controlMean | controlStd | controlKSP | ROCAUC | |
|---|---|---|---|---|---|---|
| V474_NBI | 3.40e+00 | 3.13e-01 | 2.68e+00 | 5.48e-01 | 0.2221 | 0.912 |
| V492_NBI | 4.74e-01 | 1.31e-01 | 2.68e-01 | 8.02e-02 | 0.6487 | 0.908 |
| V169_WL | 1.20e+03 | 6.66e+02 | 4.03e+02 | 4.20e+02 | 0.0543 | 0.897 |
| V474_WL | 3.19e+00 | 4.57e-01 | 2.36e+00 | 5.29e-01 | 0.9972 | 0.882 |
| V499_NBI | 7.46e-02 | 2.83e-02 | 1.34e-01 | 4.82e-02 | 0.8421 | 0.873 |
| La_V69_WL | 1.03e-03 | 1.66e-03 | -1.02e-03 | 1.56e-03 | 0.3074 | 0.872 |
| V280_NBI | 4.18e+02 | 3.20e+02 | 1.37e+02 | 7.23e+01 | 0.4410 | 0.870 |
| V473_NBI | 1.22e-01 | 4.19e-02 | 2.12e-01 | 1.67e-01 | 0.0188 | 0.865 |
| V499_WL | 1.04e-01 | 4.95e-02 | 1.99e-01 | 8.56e-02 | 0.6162 | 0.858 |
| V480_WL | 3.86e+01 | 1.15e+01 | 2.41e+01 | 7.91e+00 | 0.4542 | 0.855 |
| La_V200_NBI | -1.08e+03 | 2.09e+03 | 1.03e+03 | 2.22e+03 | 0.0393 | 0.835 |
| La_V500_WL | 9.13e-01 | 2.66e-02 | 9.49e-01 | 2.80e-02 | 0.8294 | 0.833 |
| La_V27_NBI | 9.48e-04 | 5.84e-04 | 1.73e-03 | 5.82e-04 | 0.9547 | 0.831 |
| La_V260_NBI | -3.87e+01 | 3.91e+01 | -1.46e+01 | 1.30e+01 | 0.3994 | 0.820 |
dc <- getLatentCoefficients(DEdataframe)
fscores <- attr(DEdataframe,"fscore")
pander::pander(c(mean=mean(sapply(dc,length)),total=length(dc),fraction=length(dc)/(ncol(dataframe)-1)))
| mean | total | fraction |
|---|---|---|
| 2.36 | 527 | 0.722 |
theCharformulas <- attr(dc,"LatentCharFormulas")
topvar <- rownames(tableRaw)
finalTable <- rbind(finalTable,tableRaw[topvar[!(topvar %in% topLAvar)],univariate_columns])
orgnamez <- rownames(finalTable)
orgnamez <- str_remove_all(orgnamez,"La_")
finalTable$RAWAUC <- univarRAW$orderframe[orgnamez,"ROCAUC"]
finalTable$DecorFormula <- theCharformulas[rownames(finalTable)]
finalTable$fscores <- fscores[rownames(finalTable)]
finalTable$varratio <- varratio[rownames(finalTable)]
Final_Columns <- c("DecorFormula","caseMean","caseStd","controlMean","controlStd","controlKSP","ROCAUC","RAWAUC","fscores","varratio")
finalTable <- finalTable[order(-finalTable$ROCAUC),]
pander::pander(finalTable[,Final_Columns])
| DecorFormula | caseMean | caseStd | controlMean | controlStd | controlKSP | ROCAUC | RAWAUC | fscores | varratio | |
|---|---|---|---|---|---|---|---|---|---|---|
| V172_WL | NA | 3.55e+03 | 1.78e+03 | 1.05e+03 | 5.37e+02 | 0.718095 | 0.933 | 0.933 | NA | NA |
| V220_NBI | NA | 2.01e+02 | 1.20e+02 | 5.15e+01 | 2.78e+01 | 0.747592 | 0.929 | 0.929 | NA | NA |
| V220_WL | NA | 1.96e+02 | 1.07e+02 | 5.24e+01 | 4.27e+01 | 0.097268 | 0.927 | 0.927 | NA | NA |
| V477_NBI | NA | 6.18e-02 | 2.98e-02 | 1.49e-01 | 1.72e-01 | 0.000358 | 0.925 | 0.925 | NA | NA |
| V169_NBI | NA | 1.26e+03 | 8.24e+02 | 3.47e+02 | 1.99e+02 | 0.350000 | 0.920 | 0.920 | NA | NA |
| V196_NBI | NA | 4.52e+02 | 2.51e+02 | 1.34e+02 | 6.63e+01 | 0.410564 | 0.920 | 0.920 | NA | NA |
| V182_NBI | NA | 3.44e+02 | 2.17e+02 | 9.52e+01 | 4.88e+01 | 0.793090 | 0.915 | 0.915 | NA | NA |
| V470_NBI | NA | 3.79e-01 | 1.34e-01 | 1.88e-01 | 6.82e-02 | 0.948083 | 0.913 | 0.913 | NA | NA |
| V474_NBI | NA | 3.40e+00 | 3.13e-01 | 2.68e+00 | 5.48e-01 | 0.222068 | 0.912 | 0.912 | 0 | 1.0000 |
| V182_WL | NA | 3.17e+02 | 1.69e+02 | 9.65e+01 | 8.74e+01 | 0.142781 | 0.912 | 0.912 | NA | NA |
| V492_NBI | NA | 4.74e-01 | 1.31e-01 | 2.68e-01 | 8.02e-02 | 0.648736 | 0.908 | 0.908 | 2 | 1.0000 |
| V169_WL | NA | 1.20e+03 | 6.66e+02 | 4.03e+02 | 4.20e+02 | 0.054330 | 0.897 | 0.897 | 5 | 1.0000 |
| V474_WL | NA | 3.19e+00 | 4.57e-01 | 2.36e+00 | 5.29e-01 | 0.997159 | 0.882 | 0.882 | 0 | 1.0000 |
| V499_NBI | NA | 7.46e-02 | 2.83e-02 | 1.34e-01 | 4.82e-02 | 0.842141 | 0.873 | 0.873 | 1 | 1.0000 |
| La_V69_WL | - (1.863)V47_WL + V69_WL | 1.03e-03 | 1.66e-03 | -1.02e-03 | 1.56e-03 | 0.307376 | 0.872 | 0.617 | 0 | 0.1015 |
| V280_NBI | NA | 4.18e+02 | 3.20e+02 | 1.37e+02 | 7.23e+01 | 0.441009 | 0.870 | 0.870 | 6 | 1.0000 |
| V473_NBI | NA | 1.22e-01 | 4.19e-02 | 2.12e-01 | 1.67e-01 | 0.018789 | 0.865 | 0.865 | 2 | 1.0000 |
| V499_WL | NA | 1.04e-01 | 4.95e-02 | 1.99e-01 | 8.56e-02 | 0.616245 | 0.858 | 0.858 | 5 | 1.0000 |
| V480_WL | NA | 3.86e+01 | 1.15e+01 | 2.41e+01 | 7.91e+00 | 0.454234 | 0.855 | 0.855 | 5 | 1.0000 |
| La_V200_NBI | - (0.862)V184_NBI + V200_NBI | -1.08e+03 | 2.09e+03 | 1.03e+03 | 2.22e+03 | 0.039308 | 0.835 | 0.763 | -1 | 0.0406 |
| La_V500_WL | + (0.127)V497_WL + V500_WL | 9.13e-01 | 2.66e-02 | 9.49e-01 | 2.80e-02 | 0.829410 | 0.833 | 0.797 | 1 | 0.2510 |
| La_V27_NBI | + V27_NBI - (0.464)V49_NBI | 9.48e-04 | 5.84e-04 | 1.73e-03 | 5.82e-04 | 0.954721 | 0.831 | 0.588 | -1 | 0.1221 |
| La_V260_NBI | + V260_NBI - (0.177)V280_NBI | -3.87e+01 | 3.91e+01 | -1.46e+01 | 1.30e+01 | 0.399448 | 0.820 | 0.817 | 1 | 0.3079 |
featuresnames <- colnames(dataframe)[colnames(dataframe) != outcome]
pc <- prcomp(dataframe[,iscontinous],center = TRUE,scale. = TRUE,tol=0.01) #principal components
predPCA <- predict(pc,dataframe[,iscontinous])
PCAdataframe <- as.data.frame(cbind(predPCA,dataframe[,!iscontinous]))
colnames(PCAdataframe) <- c(colnames(predPCA),colnames(dataframe)[!iscontinous])
#plot(PCAdataframe[,colnames(PCAdataframe)!=outcome],col=dataframe[,outcome],cex=0.65,cex.lab=0.5,cex.axis=0.75,cex.sub=0.5,cex.main=0.75)
#pander::pander(pc$rotation)
PCACor <- cor(PCAdataframe[,colnames(PCAdataframe) != outcome])
gplots::heatmap.2(abs(PCACor),
trace = "none",
# scale = "row",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "PCA Correlation",
cexRow = 0.5,
cexCol = 0.5,
srtCol=45,
srtRow= -45,
key.title=NA,
key.xlab="Pearson Correlation",
xlab="Feature", ylab="Feature")
EFAdataframe <- dataframeScaled
if (length(iscontinous) < 2000)
{
topred <- min(length(iscontinous),nrow(dataframeScaled),ncol(predPCA)-1)
if (topred < 2) topred <- 2
uls <- fa(dataframeScaled[,iscontinous],nfactors=topred,rotate="varimax",warnings=FALSE) # EFA analysis
predEFA <- predict(uls,dataframeScaled[,iscontinous])
EFAdataframe <- as.data.frame(cbind(predEFA,dataframeScaled[,!iscontinous]))
colnames(EFAdataframe) <- c(colnames(predEFA),colnames(dataframeScaled)[!iscontinous])
EFACor <- cor(EFAdataframe[,colnames(EFAdataframe) != outcome])
gplots::heatmap.2(abs(EFACor),
trace = "none",
# scale = "row",
mar = c(5,5),
col=rev(heat.colors(5)),
main = "EFA Correlation",
cexRow = 0.5,
cexCol = 0.5,
srtCol=45,
srtRow= -45,
key.title=NA,
key.xlab="Pearson Correlation",
xlab="Feature", ylab="Feature")
}
par(op)
par(xpd = TRUE)
dataframe[,outcome] <- factor(dataframe[,outcome])
rawmodel <- rpart(paste(outcome,"~."),dataframe,control=rpart.control(maxdepth=3))
pr <- predict(rawmodel,dataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(rawmodel,main="Raw",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(rawmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,dataframe[,outcome]==0))
}
pander::pander(table(dataframe[,outcome],pr))
| 0 | 1 | |
|---|---|---|
| 0 | 17 | 4 |
| 1 | 3 | 52 |
pander::pander(ptab$detail[c(5,3,4,6),])
| statistic | est | lower | upper | |
|---|---|---|---|---|
| 5 | diag.ac | 0.908 | 0.819 | 0.962 |
| 3 | se | 0.945 | 0.849 | 0.989 |
| 4 | sp | 0.810 | 0.581 | 0.946 |
| 6 | diag.or | 73.667 | 14.963 | 362.674 |
par(op)
par(xpd = TRUE)
DEdataframe[,outcome] <- factor(DEdataframe[,outcome])
IDeAmodel <- rpart(paste(outcome,"~."),DEdataframe[,c(outcome,varlistcV)],control=rpart.control(maxdepth=3))
pr <- predict(IDeAmodel,DEdataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(IDeAmodel,main="ILAA",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(IDeAmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,DEdataframe[,outcome]==0))
}
pander::pander(table(DEdataframe[,outcome],pr))
| 0 | 1 | |
|---|---|---|
| 0 | 17 | 4 |
| 1 | 0 | 55 |
pander::pander(ptab$detail[c(5,3,4,6),])
| statistic | est | lower | upper | |
|---|---|---|---|---|
| 5 | diag.ac | 0.947 | 0.871 | 0.985 |
| 3 | se | 1.000 | 0.935 | 1.000 |
| 4 | sp | 0.810 | 0.581 | 0.946 |
| 6 | diag.or | Inf | NA | Inf |
par(op)
par(xpd = TRUE)
PCAdataframe[,outcome] <- factor(PCAdataframe[,outcome])
PCAmodel <- rpart(paste(outcome,"~."),PCAdataframe,control=rpart.control(maxdepth=3))
pr <- predict(PCAmodel,PCAdataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(PCAmodel,main="PCA",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(PCAmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,PCAdataframe[,outcome]==0))
}
pander::pander(table(PCAdataframe[,outcome],pr))
| 0 | 1 | |
|---|---|---|
| 0 | 15 | 6 |
| 1 | 2 | 53 |
pander::pander(ptab$detail[c(5,3,4,6),])
| statistic | est | lower | upper | |
|---|---|---|---|---|
| 5 | diag.ac | 0.895 | 0.803 | 0.953 |
| 3 | se | 0.964 | 0.875 | 0.996 |
| 4 | sp | 0.714 | 0.478 | 0.887 |
| 6 | diag.or | 66.250 | 12.104 | 362.601 |
par(op)
EFAdataframe[,outcome] <- factor(EFAdataframe[,outcome])
EFAmodel <- rpart(paste(outcome,"~."),EFAdataframe,control=rpart.control(maxdepth=3))
pr <- predict(EFAmodel,EFAdataframe,type = "class")
ptab <- list(er="Error",detail=matrix(nrow=6,ncol=1))
if (length(unique(pr))>1)
{
plot(EFAmodel,main="EFA",branch=0.5,uniform = TRUE,compress = TRUE,margin=0.1)
text(EFAmodel, use.n = TRUE,cex=0.75)
ptab <- epiR::epi.tests(table(pr==0,EFAdataframe[,outcome]==0))
}
pander::pander(table(EFAdataframe[,outcome],pr))
| 0 | 1 | |
|---|---|---|
| 0 | 11 | 10 |
| 1 | 0 | 55 |
pander::pander(ptab$detail[c(5,3,4,6),])
| statistic | est | lower | upper | |
|---|---|---|---|---|
| 5 | diag.ac | 0.868 | 0.771 | 0.935 |
| 3 | se | 1.000 | 0.935 | 1.000 |
| 4 | sp | 0.524 | 0.298 | 0.743 |
| 6 | diag.or | Inf | NA | Inf |
par(op)